package com.kzj.common.exceptionHandler;

import com.kzj.common.exception.MyException;
import com.kzj.common.exception.XfxhApiException;
import com.kzj.common.re.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@ControllerAdvice(annotations = {Controller.class})
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(MyException.class)
    public Result myExceptionHandler(MyException exception){
        log.error(exception.getMessage());
        return Result.error("myExceptionHandler: "+exception.getMessage());
    }
    @ExceptionHandler(XfxhApiException.class)
    Result XfxhApiExceptionHandler(XfxhApiException exception)
    {
        log.error(exception.getMessage());
        return Result.error("XfxhApiExceptionHandler: "+exception.getMessage());
    }
    @ExceptionHandler(Exception.class)
    Result ExceptionHandler(Exception exception)
    {
        log.error(exception.getMessage());
        return Result.error("ExceptionHandler:"+exception.getMessage());
    }
}
